package com.javaclimb.music.controller;

import com.alibaba.fastjson.JSONObject;
import com.javaclimb.music.domain.Rank;
import com.javaclimb.music.service.RankService;
import com.javaclimb.music.utils.Consts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 *
 *
 * */
@RestController
public class RankController {

    @Autowired
    private RankService rankService;

    /**
     * 添加评价
     * */
    //@RequestMapping(value = "/rank/add", method = RequestMethod.POST)
    @PostMapping("/rank/add")
    public Object add(Rank rank){
        JSONObject jsonObject = new JSONObject();
        boolean flag = rankService.insert(rank);
        if(flag){
            jsonObject.put(Consts.CODE, 1);
            jsonObject.put(Consts.MSG, "评价成功");
            return jsonObject;
        }
        jsonObject.put(Consts.CODE, 0);
        jsonObject.put(Consts.MSG, "评价失败");
        return jsonObject;
    }

    /**
     * 计算平均分
     * */
    @GetMapping("/rank")
    public Object rankOfSongListId(Long songListId){
        return rankService.rankOfSongListId(songListId);
    }

    /**
     * 计算平均分
     * */
    @GetMapping("/rank/isRank")
    public Object isRank(Rank rank){
        return rankService.isRank(rank);
    }

}
